home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / game / wins1726.zip / WINDOS.C < prev    next >
C/C++ Source or Header  |  1992-06-14  |  42KB  |  1,509 lines

  1. /*
  2.     Routines which simulate DOS functions in the existing
  3.     Fractint for DOS
  4. */
  5.  
  6. #include "windows.h"
  7. #include "drivinit.h"
  8. #include "fractint.h"
  9. #include "winfract.h"
  10. #include <string.h>
  11. #include <time.h>
  12. #include <stdio.h>
  13.  
  14. #ifndef WINVER
  15. #define WINVER 0x0300        /* assume Windows 3.0 SDK if not found */
  16. #endif
  17.  
  18. #ifndef TIMERINFO
  19.                 /* define TIMERINFO stuff, if needs be */
  20. typedef struct tagTIMERINFO {
  21.     DWORD dwSize;
  22.     DWORD dwmsSinceStart;
  23.     DWORD dwmsThisVM;
  24.     } TIMERINFO;
  25.  
  26. BOOL    far pascal TimerCount(TIMERINFO FAR *);
  27. #endif
  28.  
  29. extern unsigned int windows_version;    /* 0x0300 = Win 3.0, 0x030A = 3.1 */
  30.  
  31.  
  32. int  farread(int, LPSTR, WORD);
  33. int  farwrite(int, LPSTR, WORD);
  34.  
  35. extern unsigned char FullPathName[];
  36. extern int FileFormat;
  37.  
  38. int save_system;       /* tag identifying Fractint for Windows */
  39. int save_release;       /* tag identifying version number */
  40. extern int win_release;    /* tag identifying version number  (in WINDOS2.C) */
  41.  
  42. extern BOOL bTrack, bMove;         /* TRUE if user is selecting a region */
  43. extern BOOL zoomflag;             /* TRUE is a zoom-box selected */
  44.  
  45. extern HWND hwnd;             /* handle to main window */
  46. extern HANDLE hInst;
  47.  
  48. extern HANDLE hAccTable;             /* handle to accelerator table */
  49.  
  50. extern char szHelpFileName[];         /* Help file name*/
  51.  
  52. extern int xdots, ydots, colors, maxiter;
  53. extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  54. extern int win_xdots, win_ydots;
  55.  
  56. extern int last_written_y;         /* last line written */
  57. extern int screen_to_be_cleared;     /* clear screen flag */
  58.  
  59. extern int time_to_act;          /* time to take some action? */
  60. extern int time_to_restart;         /* time to restart?  */
  61. extern int time_to_resume;         /* time to resume? */
  62. extern int time_to_quit;         /* time to quit? */
  63. extern int time_to_reinit;         /* time to reinitialize? */
  64. extern int time_to_load;         /* time to load? (DECODE) */
  65. extern int time_to_save;         /* time to save? (ENCODE) */
  66. extern int time_to_print;         /* time to print? (PRINTER) */
  67. extern int time_to_cycle;         /* time to begin color-cycling? */
  68. extern int time_to_starfield;        /* time to make a starfield? */
  69. extern int time_to_orbit;            /* time to activate orbits? */
  70.  
  71. extern unsigned char dacbox[256][3];
  72.  
  73. extern BOOL win_systempaletteused;    /* flag system palette set */
  74.  
  75. extern unsigned char far temp_array[];     /* temporary spot for Encoder rtns */
  76.  
  77. extern HANDLE hpixels;            /* handle to the DIB pixels */
  78. extern unsigned char huge *pixels;   /* the device-independent bitmap pixels */
  79. int pixels_per_byte;             /* pixels/byte in the pixmap */
  80. long pixels_per_bytem1;          /* pixels / byte - 1 (for ANDing) */
  81. int pixelshift_per_byte;         /* 0, 1, 2, or 3 */
  82. int bytes_per_pixelline;         /* pixels/line / pixels/byte */
  83. long win_bitmapsize;             /* bitmap size, in bytes */
  84.  
  85. extern int win_overlay3d;
  86. extern int win_display3d;
  87.  
  88. extern void center_window(HWND,int,int);
  89.  
  90. /****************************************************************************
  91.  
  92.     FUNCTION: keypressed(), getakey()
  93.  
  94.     PURPOSE:
  95.      keypressed()
  96.           Checks for, and processes, messages.
  97.           Returns -1 if it's time to wrap up and go home.
  98.           Returns 0 otherwise.
  99.     getakey()
  100.           same, but doesn't return until it's time to.
  101.  
  102.  
  103. ****************************************************************************/
  104.  
  105. BOOL dont_wait_for_a_key = TRUE;
  106.  
  107. #ifdef __BORLANDC__
  108.  
  109. /* Too many functions defaulting to a type 'int' return that should be
  110.    a type 'void'.  I'll just get rid of the warning message for this file
  111.    only.  MCP 8-6-91 */
  112.  
  113.    #pragma warn -rvl
  114.  
  115.    int LPTNumber;
  116.    int stackavail() { return(10240 + (signed int)_SP); }
  117. #else
  118.    int printf() {}
  119.    int _bios_serialcom(){}
  120. #endif
  121.  
  122.  
  123. extern int far wintext_textmode, far wintext_AltF4hit;
  124.  
  125. int getakey()
  126. {
  127. int i;
  128.  
  129. if (time_to_orbit) {  /* activate orbits? */
  130.     zoomflag = FALSE;
  131.     time_to_orbit = 0;
  132.     i = 'o';
  133.     return(i);
  134.     }
  135.  
  136. dont_wait_for_a_key = FALSE;
  137. i = keypressed();
  138. dont_wait_for_a_key = TRUE;
  139. zoomflag = FALSE;
  140. return(i);
  141.  
  142. }
  143.  
  144. int keypressed()
  145. {
  146. MSG msg;
  147.  
  148. /* is a text-mode screen active? */
  149. if (wintext_textmode == 2 || wintext_AltF4hit) {
  150.     if (dont_wait_for_a_key)
  151.         return(fractint_getkeypress(0));
  152.     else
  153.         return(fractint_getkeypress(1));
  154.     }
  155.  
  156. if (dont_wait_for_a_key)
  157.     if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
  158.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  159.         time_to_load+time_to_save+time_to_print+time_to_cycle+
  160.         time_to_resume+time_to_starfield;
  161.     if (time_to_orbit) {  /* activate orbits? */
  162.         time_to_act = 'o';
  163.         }
  164.     /* bail out if nothing is happening */
  165.     return(time_to_act);
  166.     }
  167.  
  168. while (GetMessage(&msg, NULL, NULL, NULL)) {
  169.  
  170.     if (!TranslateAccelerator(hwnd, hAccTable, &msg)) {
  171.         TranslateMessage(&msg);
  172.         DispatchMessage(&msg);
  173.         }
  174.  
  175.     CheckMathTools();
  176.     if (!bTrack && !bMove) {          /* don't do this if mouse-button is down */
  177.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  178.         time_to_load+time_to_save+time_to_print+time_to_cycle+
  179.         time_to_starfield;
  180.     if (time_to_orbit) {  /* activate orbits? */
  181.         time_to_act = 'o';
  182.         }
  183.     if (dont_wait_for_a_key || time_to_act)
  184.         return(time_to_act);
  185.     }
  186.  
  187.     }
  188.  
  189. if (!dont_wait_for_a_key)
  190.     time_to_quit = 1;
  191.  
  192.     /* bail out if nothing is happening */
  193.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  194.     time_to_load+time_to_save+time_to_print+time_to_cycle;
  195.     if (time_to_orbit) {  /* activate orbits? */
  196.         time_to_act = 'o';
  197.         }
  198.     return(time_to_act);
  199.  
  200. }
  201.  
  202. int  farread(int handle, LPSTR buf, WORD len)
  203. {
  204. int i;
  205.  
  206.     i = _lread(handle, buf, len);
  207.     return(i);
  208.  
  209. }
  210.  
  211. int  farwrite(int handle, LPSTR buf, WORD len)
  212. {
  213.  
  214.     return(_lwrite(handle, buf, len));
  215.  
  216. }
  217.  
  218.  
  219. /****************************************************************************
  220.  
  221.     FUNCTION: putcolor(int x, int y, int color), getcolor(int x, int y)
  222.  
  223.     PURPOSE:
  224.     putcolor:
  225.        sets the "color" value of the pixel at location x,y
  226.        (actually, a palette value)
  227.     getcolor:
  228.        returns the "color" value of the pixel at location x,y
  229.        (actually, a palette value)
  230.  
  231. ****************************************************************************/
  232.  
  233. extern int win_fastupdate;
  234.  
  235. time_t last_time;
  236. time_t update_time;
  237. long minimum_update;
  238. long pixelsout;
  239. int top_changed, bottom_changed;
  240.  
  241. /* Made global, MCP 6-16-91 */
  242. unsigned char win_andmask[8];
  243. unsigned char win_notmask[8];
  244. unsigned char win_bitshift[8];
  245.  
  246. void putcolor(int x, int y, int color)
  247. {
  248. RECT tempRect;             /* temporary rectangle structure */
  249. long i;
  250. int temp_top_changed, temp_bottom_changed;
  251. time_t this_time;
  252.  
  253. last_written_y = y;
  254. if (y < top_changed) top_changed = y;
  255. if (y > bottom_changed) bottom_changed = y;
  256.  
  257. i = win_ydots-1-y;
  258. i = (i * win_xdots) + x;
  259.  
  260. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  261.     if (pixelshift_per_byte == 0) {
  262.       pixels[i] = color % colors;
  263.       }
  264.      else {
  265.       unsigned int j;
  266.       j = i & pixels_per_bytem1;
  267.       i = i >> pixelshift_per_byte;
  268.       pixels[i] = (pixels[i] & win_notmask[j]) +
  269.           (((unsigned char)(color % colors)) << win_bitshift[j]);
  270.       }
  271.  
  272.      /* check the time every nnn pixels */
  273.      if (win_fastupdate || ++pixelsout > 100) {
  274.       pixelsout = 0;
  275.       this_time = time(NULL);
  276.       /* time to update the screen? */
  277.       if (win_fastupdate || (this_time - last_time) > update_time ||
  278.           (minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
  279.           temp_top_changed = top_changed - win_yoffset;
  280.           temp_bottom_changed = bottom_changed - win_yoffset;
  281.           if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
  282.           if (temp_top_changed    < 0) temp_top_changed    = 0;
  283.           if (temp_bottom_changed < 0) temp_bottom_changed = 0;
  284.           if (temp_top_changed    > ypagesize) temp_top_changed    = ypagesize;
  285.           if (temp_bottom_changed > ypagesize) temp_bottom_changed = ypagesize;
  286.           tempRect.top = temp_top_changed;
  287.           tempRect.bottom = temp_bottom_changed+1;
  288.           tempRect.left = 0;
  289.           tempRect.right = xdots;
  290.                   if (win_fastupdate == 1) {
  291.                       tempRect.left =  x-win_xoffset;
  292.                       tempRect.right = x-win_xoffset+1;
  293.                       }
  294.           if (win_fastupdate) {
  295.                       extern int kbdcount;
  296.                       if (kbdcount > 5)
  297.                           kbdcount = 5;
  298.               win_fastupdate = 1;
  299.               }
  300.           InvalidateRect(hwnd, &tempRect, FALSE);
  301. /*
  302.                   EndDeferWindowPos(BeginDeferWindowPos(0));
  303. */
  304.           keypressed();    /* force a look-see at the screen */
  305.           }
  306.           last_time = this_time;
  307.           top_changed = win_ydots;
  308.           bottom_changed = 0;
  309.           }
  310.       }
  311.      }
  312.  
  313. }
  314.  
  315. int getcolor(int x, int y)
  316. {
  317. long i;
  318.  
  319. i = win_ydots-1-y;
  320. i = (i * win_xdots) + x;
  321.  
  322. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  323.     if (pixelshift_per_byte == 0) {
  324.       return(pixels[i]);
  325.       }
  326.      else {
  327.       unsigned int j;
  328.       j = i & pixels_per_bytem1;
  329.       i = i >> pixelshift_per_byte;
  330.       return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
  331.       }
  332.      }
  333. else
  334.      return(0);
  335. }
  336.  
  337. int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  338. {
  339. int i, len;
  340. long startloc;
  341.  
  342. len = rightpt - leftpt;
  343. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  344. startloc = win_ydots-1-rownum;
  345. startloc = (startloc * win_xdots) + leftpt;
  346.  
  347. if (rownum < 0 || rownum >= ydots || leftpt < 0) {
  348.     return(0);
  349.     }
  350.  
  351. if (pixelshift_per_byte == 0) {
  352.     for (i = 0; i <= len; i++)
  353.     pixels[startloc+i] = localvalues[i];
  354.     }
  355. else {
  356.     unsigned int j;
  357.     long k;
  358.     for (i = 0; i <= len; i++) {
  359.     k = startloc + i;
  360.     j = k & pixels_per_bytem1;
  361.     k = k >> pixelshift_per_byte;
  362.     pixels[k] = (pixels[k] & win_notmask[j]) +
  363.         (((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
  364.     }
  365.     }
  366. pixelsout += len;
  367. if (win_fastupdate)
  368.     win_fastupdate = 2;  /* force 'putcolor()' to update a whole scanline */
  369. putcolor(leftpt, rownum, localvalues[0]);
  370. }
  371.  
  372. int get_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  373. {
  374. int i, len;
  375. long startloc;
  376.  
  377. len = rightpt - leftpt;
  378. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  379. startloc = win_ydots-1-rownum;
  380. startloc = (startloc * win_xdots) + leftpt;
  381.  
  382. if (rownum < 0 || rownum >= ydots || leftpt < 0 || rightpt >= xdots) {
  383.     for (i = 0; i <= len; i++)
  384.     localvalues[i] = 0;
  385.     return(0);
  386.     }
  387.  
  388. if (pixelshift_per_byte == 0) {
  389.     for (i = 0; i <= len; i++)
  390.     localvalues[i] = pixels[startloc+i];
  391.     }
  392. else {
  393.     unsigned int j;
  394.     long k;
  395.     for (i = 0; i <= len; i++) {
  396.     k = startloc + i;
  397.     j = k & pixels_per_bytem1;
  398.     k = k >> pixelshift_per_byte;
  399.     localvalues[i] = (pixels[k] & win_andmask[j]) >> win_bitshift[j];
  400.     }
  401.     }
  402. }
  403.  
  404. extern int rowcount;
  405.  
  406. int out_line(unsigned char *localvalues, int numberofdots)
  407. {
  408.     put_line(rowcount++, 0, numberofdots, localvalues);
  409. }
  410.  
  411. extern LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  412.  
  413. int clear_screen(int forceclear)
  414. {
  415. long numdots;
  416. int i;
  417.  
  418. /* set up the videoentry values */
  419. strcpy(videoentry.name,   "Windows Video Image");
  420. strcpy(videoentry.comment,"Generated using Winfract");
  421. videoentry.keynum      = 40;
  422. videoentry.videomodeax = 3;
  423. videoentry.videomodebx = 0;
  424. videoentry.videomodecx = 0;
  425. videoentry.videomodedx = 0;
  426. videoentry.dotmode     = 1;
  427. videoentry.xdots       = xdots;
  428. videoentry.ydots       = ydots;
  429. videoentry.colors      = colors;
  430.  
  431. win_xdots = (xdots+3) & 0xfffc;
  432. win_ydots = ydots;
  433. pixelshift_per_byte = 0;
  434. pixels_per_byte   = 1;
  435. pixels_per_bytem1 = 0;
  436. if (colors == 16) {
  437.     win_xdots = (xdots+7) & 0xfff8;
  438.     pixelshift_per_byte = 1;
  439.     pixels_per_byte = 2;
  440.     pixels_per_bytem1 = 1;
  441.     win_andmask[0] = 0xf0;  win_notmask[0] = 0x0f; win_bitshift[0] = 4;
  442.     win_andmask[1] = 0x0f;  win_notmask[1] = 0xf0; win_bitshift[1] = 0;
  443.     }
  444. if (colors == 2) {
  445.     win_xdots = (xdots+31) & 0xffe0;
  446.     pixelshift_per_byte = 3;
  447.     pixels_per_byte = 8;
  448.     pixels_per_bytem1 = 7;
  449.     win_andmask[0] = 0x80;  win_notmask[0] = 0x7f; win_bitshift[0] = 7;
  450.     for (i = 1; i < 8; i++) {
  451.     win_andmask[i] = win_andmask[i-1] >> 1;
  452.     win_notmask[i] = (win_notmask[i-1] >> 1) + 0x80;
  453.     win_bitshift[i] = win_bitshift[i-1] - 1;
  454.     }
  455.     }
  456.  
  457. numdots = (long)win_xdots * (long) win_ydots;
  458. update_time = 2;
  459. /* disable the long delay logic 
  460. if (numdots > 200000L) update_time = 4;
  461. if (numdots > 400000L) update_time = 8;
  462. */
  463. last_time = time(NULL) - update_time + 1;
  464. minimum_update = 7500/xdots;    /* assume 75,000 dots/sec drawing speed */
  465.  
  466. last_written_y = -1;
  467. pixelsout = 0;
  468. top_changed = win_ydots;
  469. bottom_changed = 0;
  470.  
  471. bytes_per_pixelline = win_xdots >> pixelshift_per_byte;
  472.  
  473. /* Create the Device-independent Bitmap entries */
  474. pDibInfo->bmiHeader.biWidth  = win_xdots;
  475. pDibInfo->bmiHeader.biHeight = win_ydots;
  476. pDibInfo->bmiHeader.biSizeImage = (DWORD)bytes_per_pixelline * win_ydots;
  477. pDibInfo->bmiHeader.biBitCount = 8 / pixels_per_byte;
  478.  
  479. /* hard to believe, but this is the fast way to clear the pixel map */
  480. if (hpixels) {
  481.      GlobalUnlock(hpixels);
  482.      GlobalFree(hpixels);
  483.      }
  484.  
  485. win_bitmapsize = (numdots >> pixelshift_per_byte)+1;
  486.  
  487. if (!(hpixels = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, win_bitmapsize)))
  488.      return(0);
  489. if (!(pixels = (char huge *)GlobalLock(hpixels))) {
  490.      GlobalFree(hpixels);
  491.      return(0);
  492.      }
  493.  
  494. /* adjust the colors for B&W or default */
  495. if (colors == 2) {
  496.     dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 0;
  497.     dacbox[1][0] = dacbox[1][1] = dacbox[1][2] = 63;
  498.     spindac(0,1);
  499.     }
  500. else
  501.     restoredac();   /* color palette */
  502.  
  503. screen_to_be_cleared = 1;
  504. InvalidateRect(hwnd, NULL, TRUE);
  505.  
  506. if (forceclear)
  507.     keypressed();        /* force a look-see at the screen */
  508.  
  509. return(1);
  510. }
  511.  
  512. int flush_screen()
  513. {
  514.  
  515. last_written_y = 0;
  516.  
  517. InvalidateRect(hwnd, NULL, FALSE);
  518.  
  519. }
  520.  
  521. /****************************************************************************
  522.  
  523.     FUNCTION: buzzer(int buzzertype)
  524.  
  525.     PURPOSE:
  526.           make some sort of sound (hey, we do what we can)
  527.  
  528. ****************************************************************************/
  529.  
  530. void buzzer(int i)
  531. {
  532.  
  533. MessageBeep(0);
  534.  
  535. }
  536.  
  537. /****************************************************************************
  538.  
  539.     FUNCTION: unsigned char far * farmemalloc(long bytecount)
  540.           void farmemfree(unsigned char * bytepointer)
  541.     PURPOSE:
  542.           allocate and free memory in a manner consistent with
  543.           Fractint for DOS
  544.  
  545. ****************************************************************************/
  546.  
  547. #define MAXFARMEMALLOCS  50        /* max active farmemallocs */
  548. int   farmemallocinit = 0;        /* any memory been allocated yet?   */
  549. HANDLE farmemallochandles[MAXFARMEMALLOCS];            /* handles  */
  550. void far *farmemallocpointers[MAXFARMEMALLOCS]; /* pointers */
  551.  
  552. void far * farmemalloc(long bytecount)
  553. {
  554. int i;
  555. HANDLE temphandle;
  556. unsigned char far *temppointer;
  557.  
  558. if (!farmemallocinit) {     /* never been here yet - initialize */
  559.     farmemallocinit = 1;
  560.     for (i = 0; i < MAXFARMEMALLOCS; i++) {
  561.     farmemallochandles[i] = (HANDLE)0;
  562.     farmemallocpointers[i] = NULL;
  563.     }
  564.     }
  565.  
  566. for (i = 0; i < MAXFARMEMALLOCS; i++)  /* look for a free handle */
  567.     if (farmemallochandles[i] == (HANDLE)0) break;
  568.  
  569. if (i == MAXFARMEMALLOCS)    /* uh-oh - no more handles */
  570.    return(NULL);        /* can't get far memory this way */
  571.  
  572. if (!(temphandle = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, bytecount)))
  573.      return(NULL);        /* can't allocate the memory */
  574. if (!(temppointer = (unsigned char far *)GlobalLock(temphandle))) {
  575.      GlobalFree(temphandle);
  576.      return(NULL);        /* ?? can't lock the memory ?? */
  577.      }
  578.  
  579. farmemallochandles[i] =  temphandle;
  580. farmemallocpointers[i] = temppointer;
  581. return(temppointer);
  582. }
  583.  
  584. void farmemfree(void far *bytepointer)
  585. {
  586. int i;
  587.  
  588. if (bytepointer == (void far *)NULL) return;
  589.  
  590. for (i = 0; i < MAXFARMEMALLOCS; i++)    /* search for a matching pointer */
  591.     if (farmemallocpointers[i] == bytepointer)
  592.      break;
  593. if (i < MAXFARMEMALLOCS) {        /* got one */
  594.     GlobalUnlock(farmemallochandles[i]);
  595.     GlobalFree(farmemallochandles[i]);
  596.     farmemallochandles[i] = (HANDLE)0;
  597.     }
  598.  
  599. }
  600.  
  601. debugmessage(char *msg1, char *msg2)
  602. {
  603. MessageBox (
  604.     GetFocus(),
  605.     msg2,
  606.     msg1,
  607.     MB_ICONASTERISK | MB_OK);
  608.  
  609. }
  610.  
  611. texttempmsg(char *msg1)
  612. {
  613. MessageBox (
  614.     GetFocus(),
  615.     msg1,
  616.     "Encoder",
  617.     MB_ICONASTERISK | MB_OK);
  618. }
  619.  
  620. stopmsg(int flags, unsigned char far *msg1)
  621. {
  622. int result;
  623.  
  624. if (! (flags & 4)) MessageBeep(0);
  625.  
  626. result = IDOK;
  627.  
  628. if (!(flags & 2))
  629.     MessageBox (
  630.     NULL,
  631.     msg1,
  632.     "Fractint for Windows",
  633.     MB_TASKMODAL | MB_ICONASTERISK | MB_OK);
  634. else
  635.     result = MessageBox (
  636.     NULL,
  637.     msg1,
  638.     "Fractint for Windows",
  639.     MB_TASKMODAL | MB_ICONQUESTION | MB_OKCANCEL);
  640.  
  641. if (result == 0 || result == IDOK || result == IDYES)
  642.     return(0);
  643. else
  644.     return(-1);
  645. }
  646.  
  647. extern char readname[];
  648. extern int fileydots, filexdots, filecolors;
  649. extern int     iNumColors;    /* Number of colors supported by device           */
  650. extern int     iRasterCaps;   /* Raster capabilities                   */
  651.  
  652. win_load()
  653. {
  654. int i;
  655.  
  656. time_to_load = 0;
  657.  
  658.     start_wait();
  659.     if ((i = read_overlay()) >= 0 && (!win_display3d ||
  660.     xdots < filexdots || ydots < fileydots)) {
  661.     if (win_display3d) stopmsg(0,
  662.         "3D and Overlay3D file image sizes must be\nat least as large as the display image.\nAltering your display image to match the file.");
  663.     xdots = filexdots;
  664.     ydots = fileydots;
  665.     colors = filecolors;
  666.     if (colors > 16) colors = 256;
  667.     if (colors >  2 && colors < 16) colors = 16;
  668.     if (xdots < 50) xdots = 50;
  669.     if (xdots > 2048) xdots = 2048;
  670.     if (ydots < 50) ydots = 50;
  671.     if (ydots > 2048) ydots = 2048;
  672.     set_win_offset();
  673.     clear_screen(0);
  674.     }
  675.     end_wait();
  676.     return(i);
  677. }
  678.  
  679. win_save()
  680. {
  681.     time_to_save = 0;
  682.     save_system = 1;
  683.     save_release = win_release;
  684.  
  685.     /* MCP 10-27-91 */
  686.     if(FileFormat != ID_BMP)
  687.        savetodisk(readname);
  688.     else
  689.        SaveBitmapFile(hwnd, FullPathName);
  690.     CloseStatusBox();
  691. }
  692.  
  693.  
  694. /********************    Printer logic    *********************/
  695.  
  696. static struct PRINFO { /* dynamic alloc these to avoid eating static space */
  697.     HDC printerDC;        /* printer device context */
  698.     HANDLE hdm;         /* memory handle for next, NULL if none */
  699.     LPDEVMODE dm;        /* devmode block from printer */
  700.     BOOL b_print_abort;     /* abort flag from abort routine */
  701.     HWND h_pabort_dialog;    /* handle for abort window */
  702.     char drivername[41];
  703.     char devname[61];
  704.     char outname[41];
  705.     int cur_orient;        /* current options, saved if dialog ok'd */
  706.     int cur_maxflag;
  707.     float cur_width;
  708.     int width_ok;        /* FALSE if width currently in error */
  709.     float printer_xsize;    /* size of max print area in inches */
  710.     float printer_ysize;
  711.     int printer_xpix;        /* number of pixels across max print area */
  712.     int printer_ypix;
  713.     } far *pr;
  714.  
  715. static int pr_orient  = DMORIENT_LANDSCAPE; /* user selected orientation */
  716. static int pr_maxflag = 1;            /* user selected max size?     */
  717. static float pr_width = 0;            /* user selected width     */
  718.  
  719. static void create_printer_DC()
  720. {
  721.     HDC displayDC;
  722.     float daspect, paspect;
  723.     int printer_xdots, printer_ydots;
  724.     if (pr->printerDC) /* ditch the old one first if present */
  725.     DeleteDC(pr->printerDC);
  726.     if (!pr->dm) /* no DEVMODE, an old driver? */
  727.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, NULL);
  728.     else { /* got DEVMODE block so get fancy */
  729.     if ((pr->dm->dmFields & DM_ORIENTATION))
  730.         pr->dm->dmOrientation = pr->cur_orient;
  731.     if ((pr->dm->dmFields & DM_COLOR))
  732.         pr->dm->dmColor = DMCOLOR_COLOR;
  733.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, (LPSTR)pr->dm);
  734.     }
  735.     if (pr->printerDC) { /* calculate size of max area on printer */
  736.     displayDC = GetDC(NULL);
  737.     daspect = ((float)xdots / GetDeviceCaps(displayDC,LOGPIXELSX))
  738.         / ((float)ydots / GetDeviceCaps(displayDC,LOGPIXELSY));
  739.     ReleaseDC(NULL,displayDC);
  740.     printer_xdots = GetDeviceCaps(pr->printerDC,HORZRES);
  741.     printer_ydots = GetDeviceCaps(pr->printerDC,VERTRES);
  742.     paspect = ((float)printer_xdots / GetDeviceCaps(pr->printerDC,HORZSIZE))
  743.         / ((float)printer_ydots / GetDeviceCaps(pr->printerDC,VERTSIZE));
  744.     pr->printer_xpix = printer_xdots;
  745.     pr->printer_ypix = (float)printer_xdots / daspect / paspect;
  746.     if (pr->printer_ypix > printer_ydots) {
  747.         pr->printer_xpix = (float)pr->printer_xpix * (float) printer_ydots
  748.                  / (float)pr->printer_ypix;
  749.         if (pr->printer_xpix > printer_xdots)
  750.         pr->printer_xpix = printer_xdots;
  751.         pr->printer_ypix = printer_ydots;
  752.         }
  753.     pr->printer_xsize = (float)pr->printer_xpix
  754.               / GetDeviceCaps(pr->printerDC,LOGPIXELSX);
  755.     pr->printer_ysize = (float)pr->printer_ypix
  756.               / GetDeviceCaps(pr->printerDC,LOGPIXELSY);
  757.     }
  758. }
  759.  
  760. static void show_printsizes(HWND hDlg)
  761. {
  762.     HWND tmphwnd;
  763.     char buf[80];
  764.     sprintf(buf,"(%.2f x %.2f inches)",pr->printer_xsize,pr->printer_ysize);
  765.     SetDlgItemText(hDlg,ID_PRS_MAXSIZ,buf);
  766.     if (pr->cur_width == 0 || pr->cur_width > pr->printer_xsize)
  767.     pr->cur_width = pr->printer_xsize;
  768.     sprintf(buf,"%.2f",pr->cur_width);
  769.     SetDlgItemText(hDlg,ID_PRS_WIDTH,buf);
  770.     tmphwnd = GetDlgItem(hDlg,ID_PRS_WIDTH);
  771.     EnableWindow(tmphwnd,1 ^ pr->cur_maxflag); /* grey if max selected */
  772. }
  773.  
  774. BOOL FAR PASCAL PrintDlg(HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
  775. {
  776.     int i;
  777.     HWND tmphwnd;
  778.     char buf[120];
  779.     float f;
  780.  
  781.     switch (msg) {
  782.  
  783.       case WM_INITDIALOG:
  784.     center_window(hDlg,0,0);
  785.     _fstrcpy((char far *)buf,pr->devname);
  786.     strcat(buf," on ");
  787.     _fstrcat((char far *)buf,pr->outname);
  788.     if (buf[i=strlen(buf)-1] == ':') buf[i] = 0;
  789.     SetDlgItemText(hDlg,ID_PR_DEVICE,buf);
  790.     if (!pr->dm || !(pr->dm->dmFields & DM_ORIENTATION)) {
  791.         i = 1; /* must use portrait */
  792.         tmphwnd = GetDlgItem(hDlg,ID_PRO_LANDS);
  793.         EnableWindow(tmphwnd,0);
  794.         }
  795.     else
  796.         i = (pr->cur_orient == DMORIENT_LANDSCAPE) ? 0 : 1;
  797.     CheckDlgButton(hDlg, ID_PRO_PORTR, i);
  798.     CheckDlgButton(hDlg, ID_PRO_LANDS, i ^ 1);
  799.     CheckDlgButton(hDlg, ID_PRS_MAX,  pr->cur_maxflag);
  800.     CheckDlgButton(hDlg, ID_PRS_CUST, pr->cur_maxflag ^ 1);
  801.     show_printsizes(hDlg); /* show the rest */
  802.     break;
  803.  
  804.       case WM_COMMAND:
  805.     switch (wParam) {
  806.       case IDOK:
  807.         if (pr->cur_maxflag == 0 && !pr->width_ok) {
  808.         MessageBeep(0);
  809.         SetFocus(GetDlgItem(hDlg, ID_PRS_WIDTH));
  810.         break;
  811.         }
  812.         EndDialog(hDlg, 1);
  813.         break;
  814.       case IDCANCEL:
  815.         EndDialog(hDlg, 0);
  816.         break;
  817.       case ID_PRO_PORTR:
  818.       case ID_PRO_LANDS:
  819.         pr->cur_orient = (wParam == ID_PRO_PORTR)
  820.                ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
  821.         if (pr->cur_width == pr->printer_xsize)
  822.         pr->cur_width = 0; /* force reset to match new size */
  823.         create_printer_DC();   /* new device context for new orient */
  824.         show_printsizes(hDlg); /* display new orientation sizes */
  825.         break;
  826.       case ID_PRS_MAX:
  827.       case ID_PRS_CUST:
  828.         pr->cur_maxflag = (wParam == ID_PRS_MAX) ? 1 : 0;
  829.         show_printsizes(hDlg); /* to set width field grey status */
  830.         break;
  831.       case ID_PRS_WIDTH:
  832.         switch(HIWORD(lParam)) {
  833.           case EN_KILLFOCUS:
  834.         GetDlgItemText(hDlg, ID_PRS_WIDTH, buf, 20);
  835.         i = strlen(buf);
  836.         while (i > 0 && buf[i] == ' ') --i;
  837.         buf[i] = 0;
  838.         if (sscanf(buf,"%f%c",&f) == 1 /* got a float */
  839.           && f <= pr->printer_xsize) { /* not greater than max */
  840.             pr->cur_width = f;
  841.             pr->width_ok = TRUE;
  842.             show_printsizes(hDlg); /* redisplay, formatted */
  843.             }
  844.         else /* entry invalid */
  845.             pr->width_ok = FALSE;
  846.         break;
  847.           default:
  848.         return FALSE;
  849.           }
  850.         break;
  851.       default:
  852.         return FALSE;
  853.       }
  854.     break;
  855.  
  856.       case WM_KEYDOWN:
  857.     switch (wParam) {
  858.       case VK_F1:
  859.         /* F1, shifted F1 bring up the Help Index */
  860.         WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
  861.         break;
  862.       default:
  863.         return FALSE;
  864.       }
  865.     break;
  866.  
  867.       default:
  868.     return FALSE;
  869.  
  870.       }
  871.     return TRUE;
  872. }
  873.  
  874. int FAR PASCAL PrintAbortDlg(HWND hWnd, unsigned msg, WORD wParam, LONG lParam)
  875. {
  876.     if (msg == WM_COMMAND) { /* Cancel button (Enter, Esc, Return, Space) */
  877.     pr->b_print_abort = TRUE;
  878.     DestroyWindow(hWnd);
  879.     return (TRUE);
  880.     }
  881.     if (msg == WM_INITDIALOG) {
  882.     center_window(hWnd,0,0);
  883.     SetFocus(hWnd);
  884.     return (TRUE);
  885.     }
  886.     return (FALSE);
  887. }
  888.  
  889. int FAR PASCAL PrintAbort(HDC hPr, int Code)
  890. {
  891.     MSG msg;
  892.     while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  893.     if (!IsDialogMessage(pr->h_pabort_dialog, &msg)) {
  894.         TranslateMessage(&msg);
  895.         DispatchMessage(&msg);
  896.         }
  897.     return (!pr->b_print_abort); /* return FALSE iff aborted */
  898. }
  899.  
  900. void win_print()
  901. {
  902.     HANDLE hpr;
  903.     int Return;
  904.     int printer_bandable;
  905.     long firstpixel;
  906.     RECT printerRect;
  907.     int more;
  908.     FARPROC lpPrintDlg;
  909.     FARPROC p_print_abort;
  910.     FARPROC p_pabort_dialog;
  911.     int printer_xacross, printer_yacross;
  912.  
  913.     time_to_print = 0;
  914.     hpr = GlobalAlloc(GMEM_FIXED, sizeof(struct PRINFO));
  915.     pr    = (struct PRINFO FAR *)GlobalLock(hpr);
  916.     pr->printerDC = NULL;
  917.     pr->hdm = NULL;
  918.     pr->cur_orient  = pr_orient;
  919.     pr->cur_maxflag = pr_maxflag;
  920.     pr->cur_width   = pr_width;
  921.     pr->width_ok = TRUE;
  922.  
  923.     { /* find the default printer */
  924.     char szPrinter[80];
  925.     char *szDevice, *szDriver, *szOutput;
  926.     int dmsize;
  927.     dmsize = 0;
  928.     GetProfileString ("windows", "device", "", szPrinter, sizeof(szPrinter));
  929.     if ( (szDevice = strtok (szPrinter, "," ))
  930.       && (szDriver = strtok (NULL,    ", "))
  931.       && (szOutput = strtok (NULL,    ", "))) {
  932.     char drivname[40];
  933.     HANDLE hDriver;
  934.     int (FAR PASCAL *p_ExtDeviceMode)(HWND,HANDLE,DEVMODE FAR *,LPSTR,LPSTR,DEVMODE FAR *,LPSTR,WORD);
  935.     _fstrncpy(pr->drivername,(char far *)szDriver,40);
  936.     _fstrncpy(pr->devname,     (char far *)szDevice,60);
  937.     _fstrncpy(pr->outname,     (char far *)szOutput,40);
  938.     pr->drivername[40] = 0;
  939.     pr->devname   [60] = 0;
  940.     pr->outname   [40] = 0;
  941.     strcpy(drivname,szDriver); strcat(drivname,".drv");
  942.     if ((hDriver = LoadLibrary(drivname)) >= 32) { /* else driver not found */
  943.         if ((p_ExtDeviceMode = GetProcAddress(hDriver,"ExtDeviceMode"))
  944.           && (dmsize = (*p_ExtDeviceMode)(NULL,hDriver,NULL,szDevice,szOutput,NULL,NULL,0)) > 0) {
  945.         /* load DEVMODE block */
  946.         pr->hdm = GlobalAlloc(GMEM_FIXED, dmsize);
  947.         pr->dm    = (DEVMODE FAR *)GlobalLock(pr->hdm);
  948.         (*p_ExtDeviceMode)(NULL,hDriver,pr->dm,szDevice,szOutput,NULL,NULL,DM_COPY);
  949.         }
  950.         FreeLibrary(hDriver);
  951.         }
  952.     create_printer_DC();
  953.     }
  954.     if (!pr->printerDC) {
  955.     stopmsg(0,"Can't find the printer!");
  956.     goto win_print_exit;
  957.     }
  958.     }
  959.  
  960.     /* get user options */
  961.     lpPrintDlg = MakeProcInstance((FARPROC) PrintDlg, hInst);
  962.     Return = DialogBox(hInst, "Printoptions", hwnd, lpPrintDlg);
  963.     FreeProcInstance(lpPrintDlg);
  964.     if (Return == 0) /* cancelled */
  965.     goto win_print_exit;
  966.     pr_orient  = pr->cur_orient;    /* not cancelled, remember options */
  967.     pr_maxflag = pr->cur_maxflag;
  968.     pr_width   = pr->cur_width;
  969.  
  970.     start_wait();
  971.  
  972.     printer_bandable =    GetDeviceCaps(pr->printerDC,RASTERCAPS) & RC_BANDING;
  973. /*
  974.     printer_bandable = 0;
  975. */
  976.  
  977.     /* calc print position & size, set up colors */
  978.     firstpixel = win_ydots - ydots;
  979.     firstpixel = firstpixel * bytes_per_pixelline;
  980.     printer_xacross = pr->printer_xpix;
  981.     printer_yacross = pr->printer_ypix;
  982.     if (pr->cur_maxflag == 0 && pr->cur_width != pr->printer_xsize) {
  983.     float f;
  984.     f = pr->cur_width / pr->printer_xsize;
  985.     printer_xacross = f * printer_xacross;
  986.     printer_yacross = f * printer_yacross;
  987.     }
  988.     if (GetDeviceCaps(pr->printerDC,NUMCOLORS) <= 2)
  989.     mono_dib_palette();    /* B&W stripes for B&W printers */
  990.     else
  991.     rgb_dib_palette();
  992.  
  993.     /* set up abort logic */
  994.     pr->b_print_abort = FALSE;
  995.     p_print_abort  = MakeProcInstance(PrintAbort,    hInst);
  996.     p_pabort_dialog = MakeProcInstance(PrintAbortDlg, hInst);
  997.     pr->h_pabort_dialog = CreateDialog(hInst, "Printabort", hwnd, p_pabort_dialog);
  998.     ShowWindow(pr->h_pabort_dialog, SW_NORMAL);
  999.     UpdateWindow(pr->h_pabort_dialog);
  1000.     EnableWindow(hwnd, FALSE);
  1001.     Return = Escape (pr->printerDC, SETABORTPROC, 0, (LPSTR)p_print_abort, NULL);
  1002.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1003.  
  1004.     /* print */
  1005.     Return = Escape (pr->printerDC, STARTDOC, 17, (LPSTR)"Fractint Printout", NULL);
  1006.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1007.     if (printer_bandable) {
  1008.     Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  1009.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1010.     }
  1011.     more = 1;
  1012.     while (more) {
  1013.     if (printer_bandable)
  1014.         DPtoLP(pr->printerDC, (LPPOINT) &printerRect, 2);
  1015.     Return = StretchDIBits(pr->printerDC,
  1016.         0, 0,
  1017.         printer_xacross, printer_yacross,
  1018.         0, 0,
  1019.         xdots, ydots,
  1020.         (LPSTR)&pixels[firstpixel], (LPBITMAPINFO)pDibInfo,
  1021.         DIB_RGB_COLORS, SRCCOPY);
  1022.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1023.     more = 0;
  1024.     if (printer_bandable) {
  1025.         Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  1026.         if (Return <= 0 || pr->b_print_abort) goto oops;
  1027.         more = ! (IsRectEmpty(&printerRect));
  1028.         }
  1029.     }
  1030.     Return = Escape(pr->printerDC, NEWFRAME, 0, NULL, NULL);
  1031.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1032.     Return = Escape(pr->printerDC, ENDDOC, 0, NULL, NULL);
  1033.  
  1034. oops:
  1035.     EnableWindow(hwnd, TRUE);
  1036.     DestroyWindow(pr->h_pabort_dialog);
  1037.     FreeProcInstance(p_print_abort);
  1038.     FreeProcInstance(p_pabort_dialog);
  1039.     default_dib_palette();   /* replace the palette */
  1040.     end_wait();
  1041.     if (!pr->b_print_abort) {
  1042.         char reason[80];
  1043.         strcpy(reason,"Print failed - General error or unspecified reason");
  1044.     if (Return == SP_OUTOFDISK)
  1045.         strcpy(reason,"Print failed - out of disk space");
  1046.     if (Return == SP_OUTOFMEMORY)
  1047.         strcpy(reason,"Print failed - out of memory");
  1048.     if (Return == 0)
  1049.         strcpy(reason,"Print failed -  driver doesn't have a function we need");
  1050.         stopmsg(0,reason);
  1051.     }
  1052.  
  1053. win_print_exit: /* cleanup */
  1054.     if (pr->printerDC)
  1055.     DeleteDC(pr->printerDC);
  1056.     if (pr->hdm) {
  1057.     GlobalUnlock(pr->hdm); /* DEVMODE */
  1058.     GlobalFree(pr->hdm);
  1059.     }
  1060.     GlobalUnlock(hpr); /* general vars */
  1061.     GlobalFree(hpr);
  1062.  
  1063. }
  1064.  
  1065. /*
  1066.     Delay code - still not so good for a multi-tasking environment, 
  1067.     but what the hell...
  1068. */
  1069.  
  1070. DWORD DelayCount;
  1071.  
  1072. DWORD DelayMillisecond(void)
  1073. {
  1074.    DWORD i;
  1075.  
  1076.    i = 0;
  1077.    while(i != DelayCount)
  1078.       i++;
  1079.    return(i);
  1080. }
  1081.  
  1082. void delay(DWORD milliseconds)
  1083. {
  1084.    DWORD n, i, j;
  1085.  
  1086. if (DelayCount == 0) {      /* use version 3.1's 1ms timer */
  1087.  
  1088.     TIMERINFO timerinfo;
  1089.  
  1090.     timerinfo.dwSize = sizeof(timerinfo);
  1091.     TimerCount(&timerinfo);
  1092.     n = timerinfo.dwmsSinceStart;
  1093.     i = n + milliseconds;
  1094.     for (;;) {
  1095.         keypressed();        /* let the other folks in */
  1096.         TimerCount(&timerinfo);
  1097.         j = timerinfo.dwmsSinceStart;
  1098.         if (j < n || j >= i)
  1099.             break;
  1100.         }   
  1101.  
  1102.    }
  1103. else {
  1104.    for(n = 0; n < milliseconds; n++)
  1105.       DelayMillisecond();
  1106.    }
  1107.  
  1108. }
  1109.  
  1110. void CalibrateDelay(void)
  1111. {
  1112.     DWORD Now, Time, Delta, TimeAdj;
  1113.     
  1114.     /* this logic switches tothe fast timer logic supplied by TimerCount */
  1115.     DelayCount = 0;
  1116.     return;
  1117.  
  1118.    DelayCount = 128;
  1119.  
  1120.    /* Determine the Windows timer resolution.  It's usually 38ms in
  1121.       version 3.0, but that may change latter. */
  1122.    Now = Time = GetCurrentTime();
  1123.    while(Time == Now)
  1124.       Now = GetCurrentTime();
  1125.  
  1126.    /* Logrithmic Adjust */
  1127.    Delta = Now - Time;
  1128.    Time = Now;
  1129.    while(Time == Now)
  1130.    {
  1131.       delay(Delta);
  1132.       Now = GetCurrentTime();
  1133.       if(Time == Now)
  1134.       {
  1135.          /* Resynch */
  1136.          Time = Now = GetCurrentTime();
  1137.          while(Time == Now)
  1138.             Now = GetCurrentTime();
  1139.          Time = Now;
  1140.          DelayCount <<= 1;
  1141.       }
  1142.    }
  1143.  
  1144.    /* Linear Adjust */
  1145.    Time = Now;
  1146.    TimeAdj = (DelayCount - (DelayCount >> 1)) >> 1;
  1147.    DelayCount -= TimeAdj;
  1148.    while(TimeAdj > 16)
  1149.    {
  1150.       delay(Delta);
  1151.       TimeAdj >>= 1;
  1152.       if(GetCurrentTime() == Now)
  1153.          DelayCount += TimeAdj;
  1154.       else
  1155.          DelayCount -= TimeAdj;
  1156.  
  1157.       /* Resynch */
  1158.       Time = Now = GetCurrentTime();
  1159.       while(Time == Now)
  1160.          Now = GetCurrentTime();
  1161.       Time = Now;
  1162.    }
  1163. }
  1164.  
  1165. /*
  1166.     Color-cycling logic
  1167.     includes variable-delay capabilities
  1168. */
  1169.  
  1170. extern int win_cycledir, win_cyclerand, win_cyclefreq, win_cycledelay;
  1171.  
  1172. extern HANDLE  hPal;       /* Palette Handle */
  1173. extern LPLOGPALETTE pLogPal;  /* pointer to the application's logical palette */
  1174. extern unsigned char far win_dacbox[256][3];
  1175. #define PALETTESIZE 256           /* dull-normal VGA            */
  1176.  
  1177. static int win_fsteps[] = {54, 24, 8};
  1178.  
  1179. int win_animate_flag = 0;
  1180. int win_syscolorindex[21];
  1181. DWORD win_syscolorold[21];
  1182. DWORD win_syscolornew[21];
  1183.  
  1184. extern int debugflag;
  1185.  
  1186. win_cycle()
  1187. {
  1188. int istep, jstep, fstep, step, oldstep, last, next, maxreg;
  1189. int incr, fromred, fromblue, fromgreen, tored, toblue, togreen;
  1190. HDC hDC;              /* handle to device context        */
  1191.  
  1192. fstep = 1;                /* randomization frequency    */
  1193. oldstep = 1;                /* single-step            */
  1194. step = 256;                /* single-step            */
  1195. incr = 999;                /* ready to randomize        */
  1196. maxreg = 256;                /* maximum register to rotate    */
  1197. last = maxreg-1;            /* last box that was filled    */
  1198. next = 1;                /* next box to be filled    */
  1199. if (win_cycledir < 0) {
  1200.     last = 1;
  1201.     next = maxreg;
  1202.     }
  1203. srand((unsigned)time(NULL));        /* randomize things        */
  1204.  
  1205. hDC = GetDC(GetFocus());
  1206.  
  1207. win_animate_flag = 1;
  1208. SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1209. SelectPalette (hDC, hPal, 1);
  1210.  
  1211. if ((iNumColors == 16 || debugflag == 1000) && !win_systempaletteused) {
  1212.     int i;
  1213.     DWORD white, black;
  1214.     win_systempaletteused = TRUE;
  1215.     white = 0xffffff00;
  1216.     black = 0;
  1217.     for (i = 0; i <= COLOR_ENDCOLORS; i++) {
  1218.     win_syscolorindex[i] = i;
  1219.     win_syscolorold[i] = GetSysColor(i);
  1220.     win_syscolornew[i] = black;
  1221.     }
  1222.     win_syscolornew[COLOR_BTNTEXT] = white;
  1223.     win_syscolornew[COLOR_CAPTIONTEXT] = white;
  1224.     win_syscolornew[COLOR_GRAYTEXT] = white;
  1225.     win_syscolornew[COLOR_HIGHLIGHTTEXT] = white;
  1226.     win_syscolornew[COLOR_MENUTEXT] = white;
  1227.     win_syscolornew[COLOR_WINDOWTEXT] = white;
  1228.     win_syscolornew[COLOR_WINDOWFRAME] = white;
  1229.     win_syscolornew[COLOR_INACTIVECAPTION] = white;
  1230.     win_syscolornew[COLOR_INACTIVEBORDER] = white;
  1231.     SetSysColors(COLOR_ENDCOLORS,(LPINT)win_syscolorindex,(LONG FAR *)win_syscolornew);
  1232.     SetSystemPaletteUse(hDC,SYSPAL_NOSTATIC);
  1233.     UnrealizeObject(hPal);
  1234.     }
  1235.  
  1236. while (time_to_cycle) {
  1237.     if (win_cyclerand) {
  1238.     for (istep = 0; istep < step; istep++) {
  1239.         jstep = next + (istep * win_cycledir);
  1240.         if (jstep <=      0) jstep += maxreg-1;
  1241.         if (jstep >= maxreg) jstep -= maxreg-1;
  1242.         if (++incr > fstep) {    /* time to randomize    */
  1243.         incr = 1;
  1244.         fstep = ((win_fsteps[win_cyclefreq]*
  1245.             (rand() >> 8)) >> 6) + 1;
  1246.         fromred   = dacbox[last][0];
  1247.         fromgreen = dacbox[last][1];
  1248.         fromblue  = dacbox[last][2];
  1249.         tored      = rand() >> 9;
  1250.         togreen   = rand() >> 9;
  1251.         toblue      = rand() >> 9;
  1252.         }
  1253.         dacbox[jstep][0] = fromred     + (((tored   - fromred  )*incr)/fstep);
  1254.         dacbox[jstep][1] = fromgreen + (((togreen - fromgreen)*incr)/fstep);
  1255.         dacbox[jstep][2] = fromblue  + (((toblue  - fromblue )*incr)/fstep);
  1256.         }
  1257.     }
  1258.     if (step >= 256) step = oldstep;
  1259.  
  1260.     spindac(win_cycledir,step);
  1261.     delay(win_cycledelay);
  1262.     AnimatePalette(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1263.     RealizePalette(hDC);
  1264.     keypressed();
  1265.     if (win_cyclerand == 2) {
  1266.     win_cyclerand = 1;
  1267.     step = 256;
  1268.     }
  1269.     }
  1270.  
  1271. win_animate_flag = 0;
  1272. ReleaseDC(GetFocus(),hDC);
  1273.  
  1274. }
  1275.  
  1276. /* cursor routines */
  1277.  
  1278. extern HANDLE hSaveCursor;           /* the original cursor value */
  1279. extern HANDLE hHourGlass;           /* the hourglass cursor value */
  1280.  
  1281. start_wait()
  1282. {
  1283.    hSaveCursor = SetClassWord(hwnd, GCW_HCURSOR, hHourGlass);
  1284. }
  1285.  
  1286. end_wait()
  1287. {
  1288.    SetClassWord(hwnd, GCW_HCURSOR, hSaveCursor);
  1289. }
  1290.  
  1291. /* video-mode routines */
  1292.  
  1293. extern int    viewwindow;        /* 0 for full screen, 1 for window */
  1294. extern float  viewreduction;        /* window auto-sizing */
  1295. extern float  finalaspectratio;     /* for view shape and rotation */
  1296. extern int    viewxdots,viewydots;    /* explicit view sizing */
  1297. extern int    fileydots, filexdots, filecolors;
  1298. extern float  fileaspectratio;
  1299. extern int    skipxdots,skipydots;    /* for decoder, when reducing image */
  1300.  
  1301. int get_video_mode(struct fractal_info *info)
  1302. {
  1303.    viewwindow = viewxdots = viewydots = 0;
  1304.    fileaspectratio = .75;
  1305.    skipxdots = skipydots = 0;
  1306.    return(0);
  1307. }
  1308.  
  1309.  
  1310. void spindac(int direction, int step)
  1311. {
  1312. int i, j, k;
  1313. int cycle_start, cycle_fin;
  1314. extern int rotate_lo,rotate_hi;
  1315. char tempdacbox;
  1316.  
  1317. cycle_start = 0;
  1318. cycle_fin = 255;
  1319. if (time_to_cycle) {
  1320.    cycle_start = rotate_lo;
  1321.    cycle_fin = rotate_hi;
  1322.    }
  1323.  
  1324. for (k = 0; k < step; k++) {
  1325.     if (direction > 0) {
  1326.     for (j = 0; j < 3; j++) {
  1327.         tempdacbox = dacbox[cycle_fin][j];
  1328.         for (i = cycle_fin; i > cycle_start; i--)
  1329.         dacbox[i][j] = dacbox[i-1][j];
  1330.         dacbox[cycle_start][j] = tempdacbox;
  1331.         }
  1332.     }
  1333.     if (direction < 0) {
  1334.     for (j = 0; j < 3; j++) {
  1335.         tempdacbox = dacbox[cycle_start][j];
  1336.         for (i = cycle_start; i < cycle_fin; i++)
  1337.         dacbox[i][j] = dacbox[i+1][j];
  1338.         dacbox[cycle_fin][j] = tempdacbox;
  1339.         }
  1340.     }
  1341.     }
  1342.  
  1343.     /* fill in intensities for all palette entry colors */
  1344.     for (i = 0; i < 256; i++) {
  1345.     pLogPal->palPalEntry[i].peRed    = ((BYTE)dacbox[i][0]) << 2;
  1346.     pLogPal->palPalEntry[i].peGreen = ((BYTE)dacbox[i][1]) << 2;
  1347.     pLogPal->palPalEntry[i].peBlue    = ((BYTE)dacbox[i][2]) << 2;
  1348.     pLogPal->palPalEntry[i].peFlags = PC_RESERVED;
  1349.     }
  1350.  
  1351.     if (!win_animate_flag) {
  1352.     HDC hDC;
  1353.     hDC = GetDC(GetFocus());
  1354.     SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1355.     SelectPalette (hDC, hPal, 1);
  1356.     RealizePalette(hDC);
  1357.     ReleaseDC(GetFocus(),hDC);
  1358.         /* for non-palette-based adapters, redraw the image */
  1359.     if (!iRasterCaps) {
  1360.             InvalidateRect(hwnd, NULL, FALSE);
  1361.             }
  1362.     }
  1363. }
  1364.  
  1365. restoredac()
  1366. {
  1367. int iLoop;
  1368. int j;
  1369.  
  1370.     /* fill in intensities for all palette entry colors */
  1371.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++)
  1372.     for (j = 0; j < 3; j++)
  1373.         dacbox[iLoop][j] = win_dacbox[iLoop][j];
  1374.     spindac(0,1);
  1375. }
  1376.  
  1377. extern int colorstate;
  1378. extern char    colorfile[];
  1379.  
  1380. int ValidateLuts( char * fn )
  1381. {
  1382. FILE * f;
  1383. unsigned    r, g, b, index;
  1384. unsigned char    line[101];
  1385. unsigned char    temp[81];
  1386.     strcpy (temp,fn);
  1387.     if (strchr(temp,'.') == NULL) /* Did name have an extension? */
  1388.         strcat(temp,".map");  /* No? Then add .map */
  1389.     findpath( temp, line);          /* search the dos path */
  1390.     f = fopen( line, "r" );
  1391.     if (f == NULL)
  1392.         return 1;
  1393.     for( index = 0; index < 256; index++ ) {
  1394.         if (fgets(line,100,f) == NULL)
  1395.             break;
  1396.         sscanf( line, "%d %d %d", &r, &g, &b );
  1397.         /** load global dac values **/
  1398.         dacbox[index][0] = r >> 2;    /* maps default to 8 bits */
  1399.         dacbox[index][1] = g >> 2;    /* DAC wants 6 bits */
  1400.         dacbox[index][2] = b >> 2;
  1401.     }
  1402.     fclose( f );
  1403.     colorstate = 2;
  1404.     strcpy(colorfile,temp);
  1405.     return 0;
  1406. }
  1407.  
  1408. int win_thinking = 0;
  1409.  
  1410. int thinking(int waiting, char *dummy)
  1411. {
  1412. if (waiting && ! win_thinking) {
  1413.     win_thinking = 1;
  1414.     start_wait();
  1415.     }
  1416. if (!waiting)
  1417.     end_wait();
  1418. return(keypressed());
  1419. }
  1420.  
  1421. extern HWND far wintext_hWndCopy;                /* a Global copy of hWnd */
  1422.  
  1423. /* Call for help caused by pressing F1 inside the "fractint-style"
  1424.    prompting routines */
  1425. int winfract_help()
  1426. {
  1427.         WinHelp(wintext_hWndCopy,szHelpFileName,HELP_INDEX,0L);
  1428. }
  1429.  
  1430. int far_strlen(char far *string) {
  1431. int i;
  1432. for (i = 0; ; i++)
  1433.     if (string[i] == 0)
  1434.     return(i);
  1435. }
  1436.  
  1437. int far_strnicmp(char far *string1, char far *string2, int maxlen) {
  1438. int i;
  1439. unsigned char j, k;
  1440. for (i = 0;i < maxlen ; i++) {
  1441.     j = string1[i];
  1442.     k = string2[i];
  1443.     if (j >= 'a' && j <= 'z') j -= ('a' - 'A');
  1444.     if (k >= 'a' && k <= 'z') k -= ('a' - 'A');
  1445.     if (j-k != 0)
  1446.     return(j-k);
  1447.     }
  1448. return(0);
  1449. }
  1450.  
  1451. int far_memcpy(void far *string1, void far *string2, int maxlen) {
  1452. int i;
  1453. for (i = 0;i < maxlen ; i++)
  1454.     ((char far *)string1)[i] = ((char far *)string2)[i];
  1455. }
  1456.  
  1457. int far_memcmp(void far *string1, void far *string2, int maxlen) {
  1458. int i;
  1459. unsigned char j, k;
  1460. for (i = 0;i < maxlen ; i++) {
  1461.     j = ((char far *)string1)[i];
  1462.     k = ((char far *)string2)[i];
  1463.     if (j-k != 0)
  1464.     return(j-k);
  1465.     }
  1466. return(0);
  1467. }
  1468.  
  1469. int far_memset(void far *string1, char char2, int maxlen) {
  1470. int i;
  1471. for (i = 0;i < maxlen ; i++)
  1472.     ((char far *)string1)[i] = char2;
  1473. }
  1474.  
  1475. /* fake/not-yet-implemented subroutines */
  1476.  
  1477. void farmessage(unsigned char far *foo) {}
  1478. void setvideomode(int foo1, int foo2, int foo3, int foo4) {}
  1479. int fromvideotable() {}
  1480. int home() {}
  1481.  
  1482. int intro_overlay() {}
  1483. int rotate_overlay() {}
  1484. int printer_overlay() {}
  1485. int pot_startdisk() {}
  1486. int SetTgaColors() {}
  1487. int startdisk() {}
  1488. int enddisk() {}
  1489. int readdisk() {}
  1490. int writedisk() {}
  1491. int nosnd(){}
  1492. int snd(){}
  1493. int targa_startdisk(){}
  1494. int targa_writedisk(){}
  1495. int targa_readdisk(){}
  1496. int SetColorPaletteName() {}
  1497. int findfont() {return(0);}
  1498. int readticker(){return(0);}
  1499. int EndTGA(){}
  1500.  
  1501. int dvid_status(){}
  1502. int tovideotable(){}
  1503.  
  1504. void load_mat(){}
  1505. void mult_vec_iit(){}
  1506. int check_vidmode_keyname(){return(0);}
  1507.  
  1508. void TranspPerPixel(){}
  1509.